﻿<!DOCTYPE html>
<html>
<!-- 课件管理-编辑 -->

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
        <script src="/static/js/common.js"></script>

</head>

<body>
    <div id="app" class="popupW100" v-cloak>
        <el-form label-position="right" :model="Form" status-icon :rules="rules" ref="ruleForm" label-width="100px"
            size="mini">
            <el-row>
                <!-- 题目名称 -->
                <el-col :span="11">
                    <div class="elst-select-mini">
                        <el-form-item prop="titleoftitle">
                            <el-input type="text" v-model="Form.titleoftitle" autocomplete="off" size="mini">
                                <template slot="prepend">
                                    {{Coursewaremanagement.Titleoftitle+mark.m}}
                                </template>
                            </el-input>
                            <span class="iputLineMust" v-if="Form.titleoftitle.length<=0">
                                <img src="/static/images/exclamation.png" alt="">
                            </span>
                        </el-form-item>
                    </div>
                </el-col>
                <!-- 题型: -->
                <el-col :span="11" offset="2">
                    <el-col>
                        <div class="elst-select-mini">
                            <el-form-item  prop="questiontype">
                                <el-input size="mini">
                                    <template slot="prepend">
                                        <div> {{Coursewaremanagement.Questiontype+mark.m}}</div>
                                    </template>
                                    <el-select @visible-change="visibleChange" v-model="Form.questiontype" slot="suffix"
                                               :placeholder="Coursewaremanagement.Questiontype">
                                        <el-option label="请选择" value=""></el-option>
                                        <el-option v-for="item in QuestiontypeL" :label="item.value" :value="item.key">
                                        </el-option>
                                    </el-select>
                                </el-input>
                                <span class="iputLineMust" v-if="Form.questiontype.length<=0">
                                    <img src="/static/images/exclamation.png" alt="">
                                </span>

                            </el-form-item>
                        </div>
                    </el-col>
                </el-col>
                <el-col class="head-tool">
                    <el-button type="primary" @click="UserInput('tj')">{{col.btnAddItem}}</el-button>
                </el-col>
                <el-col span="24">
                    <el-table :data="Form.zB_QuestionsOptions" border>
                        <!-- 选项名称 -->
                        <el-table-column prop="option" :label="Coursewaremanagement.OptionName" min-width="180">
                        </el-table-column>
                        <!-- 选项内容 -->
                        <el-table-column prop="content" :label="Coursewaremanagement.OptionComment" min-width="180">
                        </el-table-column>
                        <!-- 答案 -->
                        <!--<el-table-column prop="" align="center" label="答案">
                            <template slot-scope="scope">
                                <el-select @visible-change="visibleChange" @change="handleSelect" v-model="scope.row.IsAnswer" placeholder="请选择">
                                    <el-option v-for="item in Coursewaremanagement" :key="item.key" :label="item.value"
                                               :value="item.key"></el-option>
                                </el-select>
                            </template>
                        </el-table-column>-->

                        <el-table-column prop="isAnswer" align="center" label="答案" min-width="150">

                        </el-table-column>


                        <!--<el-table-column label="操作">
                            <template slot-scope="scope">
                                <el-button @click.native.prevent="deleteRow(scope.$index, Form.OptionsList)" type="text"
                                           size="small">
                                    移除
                                </el-button>
                            </template>
                        </el-table-column>-->

                        <el-table-column label="操作" width="50">
                            <template slot-scope="scope">
                                <el-button @click.native.prevent="deleteRow(scope.$index, Form.zB_QuestionsOptions)" type="text"
                                           size="small">
                                    移除
                                </el-button>
                            </template>
                        </el-table-column>




                    </el-table>
                </el-col>
            </el-row>
            <br>
            <el-row type="flex" justify="end">
                <el-form-item>
                    <el-button type="primary" @click="onSubmitForm('ruleForm')">{{col.btnCommit}}</el-button>
                    <el-button type="primary" @click="parent.ListItem.dialogVisible=false">{{col.btnBack}}</el-button>
                </el-form-item>
            </el-row>
            <el-dialog title="课件试题选项" fullscreen="true" :visible.sync="ListItem.dialogVisible" @close='closeDialog' width="95%" height="50%"
                top="10vh">
                <iframe ref="iframe" :src="ListItem.InputUrl" style="height:100%;width:100%" frameborder="0"></iframe>
            </el-dialog>
        </el-form>
    </div>
    <script type="text/javascript">
        var app = new Vue({
            el: '#app',
            data: {
                //父业传参
                id: '',
                value1: '',
                ListItem: ListItem,
                QuestiontypeL: [],//题型下拉
                //业务表单内容
                Form: {
                    zBCourseId: null,//课件ID
                    id: guidEmpty,
                    titleoftitle: '',
                    questiontype:'',
                    //OptionsList: [],//选项
                    ///////////////////////
                    zB_QuestionsOptions: [],//选项从表
                    ///////////////////////
                },
                //表单验证
                rules: {
                    titleoftitle: [
                        verification.NotNull

                    ],
                    questiontype: [
                        verification.NotNull
                    ],
                }
            },
            methods: {
                //解決edge下select bug
                visibleChange: function (isVisible) {
                    visibleChange(isVisible)
                },
                //编辑
                UserInput: function (val, id) {
                    if (!this.Form.questiontype) {

                        showMessage('请先选择试题类型！', 'error');
                        return;
                    }
                    DialogShow(this, val, "CoursewaremanagementInputtQuesOption.html", id);
                },
                getData: function () {
                    getData(this, '/api/ZB_CourseQuestions/get?id=' + this.id);
                    //this.Form.Courseware = this.Form.Courseware + "";//难度等级，圣奥总部没有
                },
                //提交数据
                onSubmitForm: function (formName) {
                    var mythis = this;
                    this.$refs[formName].validate(function (valid) {
                        //验证通过
                        if (valid) {
                            //判断是否有题目
                            if (mythis.Form.zB_QuestionsOptions.length <= 1) {

                                showMessage('请添加选项信息！', 'error');
                                return false;

                            }
                            var num = 0;
                            for (var i = 0; i < mythis.Form.zB_QuestionsOptions.length; i++) {
                                if (mythis.Form.zB_QuestionsOptions[i].isAnswer == "是") {
                                    num++;
                                }

                            }
                            //判断是否有正确选项
                            if (num == 0) {
                                showMessage('请至少添加一个正确的选项！', 'error');
                                return false;

                            }

                            //判断如果非多选 则不能有多个正确选项
                            if (mythis.Form.questiontype != '1' && num > 1) {
                                showMessage('非多选题目只能有一个正确选项！', 'error');
                                return false;

                            }
                            //如果是判断题 只能有两个选项
                            if (mythis.Form.questiontype == '2' && mythis.Form.zB_QuestionsOptions.length != 2) {
                                showMessage('判断题只能有两个选项！', 'error');
                                return false;

                            }
                            
                            console.log("bbbbbb",mythis.Form);
                            onSubmitForm(this, '/api/ZB_CourseQuestions/Save', mythis.Form);
                        } else {
                            //验证失败
                            return false;
                        }
                    });
                },

                handleChange: function (value) {
                    console.log(value);
                },
                handleSelect: function (ev) {
                    console.log(ev);
                },
                deleteRow: function (index, rows) {
                    rows.splice(index, 1);
                },
                indexMethod: function (index) {
                    return (this.ListItem.currentPage - 1) * this.ListItem.pagesize + index + 1;
                },
               
            },
            mounted: function () {
                //初始化数据
                //列表高度自适应
                tablehigh(this);
                this.id = getUrlParam("id");
                //alert(parent.app.sbzid);
                this.Form.zBCourseId = parent.app.sbzid;
                //alert(this.Form.zBCourseId);
                //alert(this.id);
                //获取下拉菜单内容
                var result = getDicDataArray(['zbkjgltx']);//批量取下拉
                this.QuestiontypeL = result[0].value;
                ////////////////////////////////////////
                //this.id = getUrlParam("id");
                this.getData();
                if (this.Form.zB_QuestionsOptions == null) {
                    this.Form.zB_QuestionsOptions = [];
                }

            }

        });
    </script>
</body>

</html>